/**
 * @version		$Id: installer.js 52 2011-02-09 09:46:59Z happy_noodle_boy $
 * @package		JCE
 * @copyright	Copyright (C) 2009 Ryan Demmer. All rights reserved.
 * @license		GNU/GPL
 * This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */
(function($) {
    $.jce.Installer = {
        init : function(options) {
            // Tabs
            $('#tabs').tabs();

            $('button#install_button').button({
                icons : {
                    primary : 'icon-install'
                }
            });

            $('button.install_discover.discover').button({
                icons : {
                    primary : 'icon-discover'
                }
            }).click( function(e) {
                var btn = this;
                $(this).addClass('loading');
                $.post("index.php?option=com_jce&view=installer&task=discover", {}, function(r) {
                    if (r && r.length) {
                        $('div#install_discovered').html(r).hide().fadeIn().find('tbody tr:odd').addClass('odd');
                        $('button.install_discover.install').attr('disabled', '').button('enable');
                    }
                    $(btn).removeClass('loading');
                });

                e.preventDefault();
            });

            $('button.install_discover.install').button({
                icons : {
                    primary : 'icon-install'
                }
            }).click( function(e) {
                if ($('div#install_discovered input:checkbox:checked').length) {
                    $(this).addClass('loading');
                    $('input[name="task"]').val('installDiscovered');
                    $('form').submit();
                }
                e.preventDefault();
            });

            $('button.install_uninstall').button({
                icons : {
                    primary : 'icon-remove'
                }
            }).click( function(e) {
                if ($('div#tabs input:checkbox:checked').length) {
                    $(this).addClass('loading');
                    $('input[name="task"]').val('remove');
                    $('form').submit();
                }
                e.preventDefault();
            });
        }

    }
})(jQuery);